# Spencer Allen McMillan

Member

10

111 Neutral

• Rank
Member
1. ## Rock Paper Scissors Lizard Spock in Python

So, I'm doing this assignment and I cannot figure out what I'm doing wrong. I'm supposed to find the difference between the player's number and computer's number and then use modulus division. I then use the resulting number to decide on whether the computer or the player wins the hand. For some reason though python seems to be skipping my else statement or something. Any help would be appreciated. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] [CODE] def number_to_name(number): if number == 0: name = "rock" return name elif number == 1: name = "Spock" return name elif number == 2: name = "paper" return name elif number == 3: name = "lizard" return name elif number == 4: name = "scissors" return name def name_to_number(name): if name == "rock": number = 0 return number elif name == "Spock": number = 1 return number elif name == "paper": number = 2 return number elif name == "lizard": number = 3 return number elif name == "scissors": number = 4 return number def rpsls(guess): import random player_number = name_to_number(guess) comp_number = random.randrange(0, 5) winner = (comp_number - player_number) % 5 print "" print "Player chooses " + number_to_name(player_number) print "Computer chooses " + number_to_name(comp_number) if (comp_number - player_number) % 5 == 1 or 2: print "Computer wins!" elif (comp_number - player_number) % 5 == 0: print "Player and computer tie!" else: print "Player wins!" rpsls("rock") rpsls("Spock") rpsls("paper") rpsls("lizard") rpsls("scissors") [/CODE]
2. ## Memory Allocation

Thanks Brother Bob! I shall read/practice with pointers some more.
3. ## Memory Allocation

I'm stumped. It compiles fine, but when it gets to the for function in main that prints off the array it says I don't have access to it. Here's the revised code. [CODE] #include<iostream> #include<cstdlib> #include<ctime> using namespace std; void randomArrayFill( int *a, int size ) { a = new int[size]; for( int i = 0; i < size; i++ ) { a[i] = rand() % 100; } } int main() { //----Init-------------------------------------------------------------- int size = 0; int *a = 0; srand(0); //----End Init---------------------------------------------------------- cout << "Enter the size of an array to create: "; cin >> size; randomArrayFill( a, size ); for( int i = 0; i < size; i++ ) { cout << a[i] << " "; } cin.get(); cin.get(); return 0; } [/CODE]
4. ## Memory Allocation

Thanks! I've got another issue, but I'm going to see if I can work it out before askin' another question. Thanks again! 0/
5. ## Memory Allocation

Hello, I'm learning memory allocation online right now and I'm having some issues. I'm trying to create the size of an array in run-time and I seem to be having some issues. When I code it all inline it works fine, but when I put it in a function I seem to be doing something wrong. I keep getting this error on Visual Studio: [b]error C2082: redefinition of formal parameter 'a'[/b] Here's the code. [CODE] #include<iostream> #include<cstdlib> #include<ctime> using namespace std; void randomArrayFill( int *a, int size ) { int *a = new int[size]; for( int i = 0; i < size; i++ ) { a[i] = rand() % 100; } } int main() { //----Init-------------------------------------------------------------- int size = 0; int *a = 0; srand(0); //----End Init---------------------------------------------------------- cout << "Enter the size of an array to create: "; cin >> size; randomArrayFill( a, size ); for( int i = 0; i < size; i++ ) { cout << a[i]; } cin.get(); cin.get(); return 0; } [/CODE]
6. ## -Help with some code-

Thanks Rad. I knew I should just sleep and take a look at it again, lol. And noted on the srand. I'll be sure to change that.
7. ## -Help with some code-

Code snippet wasn't cooperating. >.<
8. ## -Help with some code-

Hello, I'm workin' on a slot machine program and for some reason I'm having some issues with the menu. Selecting one breaks out of the menu loop and will allow you to play the slot machine game. Selecting two quits the game. And anything else it prints onto the console "Please enter a valid option." For some reason, when an invalid number is entered it prints but it doesn't loop back. So yeah, slightly confused. *I apologize, but the code snippet tool was not cooperating with me, only showing a portion of whatever code I put in* Here's the code: #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int Random( int, int ); int main() { //---- Initialization------------------------------------------------- int low; int high; int chips = 1000; int hold = 0; bool quit = false; //----End Init-------------------------------------------------------- // Start Game--------------------------------------------------------- while( !quit ){ //----Menu-------------------------------------------------------- while( hold <= 0 ) { cout << "Player's chips: \$" << chips << endl; cout << "1) Play slot. 2) Exit." << endl; cin >> hold; if ( hold == 1 ) break; if ( hold == 2 ) quit = true; else cout << "Please select a valid option" << endl; } //----End Menu---------------------------------------------------- } cin.get(); cin.get(); return 0; //---End Game--------------------------------------------------------- } int Random( int low, int high ) { srand(time(0)); int a = (rand() + low) % high; return a; }
9. ## Learnin' DirectX

Thanks a lot! That was actually a REALLY simple fix, lol.
10. ## Learnin' DirectX

Hello, I'm in the process of learning DirectX 11 with the book "Beginning DirectX 11 Game Programming". I'm using Microsoft Visual Studio '10 and I'm trying to get a blank window running. Here's the code I'm running: [CODE] #include <Windows.h> LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT paintStruct; HDC hDC; switch( message ) { case WM_PAINT: hDC = BeginPaint( hwnd, &paintStruct ); EndPaint( hwnd, &paintStruct ); break; case WM_DESTROY: PostQuitMessage( 0 ); break; default: return DefWindowProc( hwnd, message, wParam, lParam ); } return 0; } int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow ) { UNREFERENCED_PARAMETER( prevInstance ); UNREFERENCED_PARAMETER( cmdLine ); WNDCLASSEX wndClass = {0}; wndClass.cbSize = sizeof( WNDCLASSEX ) ; wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = WndProc; wndClass.hInstance = hInstance; wndClass.hCursor = LoadCursor( NULL, IDC_ARROW ); wndClass.hbrBackground = (HBRUSH ) (COLOR_WINDOW + 1 ); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = "DX11BookWindowClass"; if( !RegisterClassEx (&wndClass ) ) return -1; RECT rc = { 0, 0, 640, 480 }; AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE ); HWND hwnd = CreateWindowA( "DX11BookWindowClass", "Blank Win32 Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom-rc.top, NULL, NULL, hInstance, NULL ); if(!hwnd) return-1; ShowWindow( hwnd, cmdShow ); // demo init MSG msg = { 0 }; while( msg.message != WM_QUIT ) { if ( PeekMessage(&msg, 00, 0, 0, PM_REMOVE) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else{ // Update // Draw } } // Demo Shutdown return static_cast<int>( msg.wParam ); } [/CODE] The error I'm receiving is: error C2440: '=' : cannot convert from 'const char [20]' to 'LPCWSTR' . For the line: wndClass.lpszClassName = "DX11BookWindowClass"; Any ideas as to how I can fix this?