int main() {
	sf::RenderWindow window(sf::VideoMode(1780, 980), "Scrolls of the Elders ");
	int stage = 0;
	srand(time(NULL));
	while (true) {
		
		PlayGame(window);
		stage++;
		//window.clear();
		cout << "Press any key to play again" << endl;
		system("pause");
	
	
	}


}
Example #2
0
void Record(int group[][COUNT_FUNC]){

    int i,j;
    char output[10000];

    memset(output,0,10000);
    record = fopen("record.txt","w");
    for ( i = 0 ; i < GROUP_SIZE ; i++){
    	sprintf(output,"%sParameter %d :",output, i);
        for ( j = 0 ; j < COUNT_FUNC ; j++){
            sprintf(output,"%s %5d",output, group[i][j]);
        }
        sprintf(output,"%s , score = %d\n",output, PlayGame(group[i]) );
    }
    fprintf(record,"%s",output);

    fclose(record);
}
Example #3
0
int main(int argc, char **argv)
{
    srand(time(NULL));
    
    if (!InitGame(argc, argv))
    {
        fprintf(stderr, "\nInitialization failed.\n");
        return -1;        
    }

    DoTitleScreen();
    DoMainMenu();

    PlayGame();

    ShutdownGame();
    
    return 0;
}
Example #4
0
void main (void)
{
	FILE * infile;
	string choice;
	class_p clas;
	ship_p ship;
	ship_p cell[NUM_ROWS][NUM_COLS];
	int ship_num;
	coord history[100];

	Randomize();
	choice=StartGame();
	infile=GetFile();
	InitCell(cell);
	InitHistory(history);
	ship=GetData(infile,&clas,&ship,&ship_num);
	
	InitGraphics();
	DrawStartingBoard(choice);
	PlacingShips(clas,ship,cell,ship_num);
	

	PlayGame(history,cell,clas,ship,ship_num,choice);
}
Example #5
0
void TitleMenu() {
  int program_quit = 0;
  char ch = '\0';
  while(!program_quit) {
    clear();
    attron(A_BOLD);
    attron(COLOR_PAIR(3));
    mvprintw(5, 25, "A S C I I     P A C K - M A N ");
    mvprintw(15, 25, "[P] PLAY GAME");
    mvprintw(16, 25, "[H] HELP");
    mvprintw(17, 25, "[Q] QUIT");
    mvprintw(13, 25, "Choose an option :");
    attroff(COLOR_PAIR(3));
    attroff(A_BOLD);

    ch = getch();
    switch(ch) {
      case 'p':
      case 'P':
        PrepareGame();
        PlayGame();
        ShowResult();
        break;
      case 'h':
      case 'H':
        ShowHelp();
        break;
      case 'q':
      case 'Q':
        program_quit = 1;
        break;
      default:
        break;
    }
  }
}
Example #6
0
int main(int argc, char ** argv) 
{
  int do_usage = 0;
  unsigned int seed = 0;  // seed for random setup of the game
  char * filename = NULL; // to load game from a file

  chdir( "/home/games/blue" );


  printf("\n     BLUE. Version 1.0.2\n"
    "     Copyright (c) 2002\n"
    "Blue comes with ABSOLUTELY NO WARRANTY.\n"
    "This software is free and you are welcome to redistribute it\n"
    "under certain conditions; for more details see the file \n"
    "COPYRIGHT included in the distribution.\n\n");

  initGUI(0);

  while (1) {
     int c;
#ifdef USE_LONG_OPTIONS
     int option_index = 0;
     static struct option long_options[] =
     {
       {"seed", 1, 0, 's'},
       {"file", 1, 0, 'f'},
       {0, 0, 0, 0}
     };

     if ( (c = getopt_long (argc, argv, "s:f:",
                        long_options, &option_index)) == -1)
#else
     if ( (c = getopt (argc, argv, "s:f:") ) == -1 )
#endif
     break;
     switch (c) {
       case 's': // seed
         seed = atoi(optarg);
         break;
       case 'f': // file
         filename = optarg;
         break;
       default:
         do_usage = 1;
     }
   }
   if (do_usage) {
     printf("Usage: blue [-f file] [-s seed]\n");
  }
/*init Game*/
  initHistory( & theHistory );
  resetStrategy();
  play_mode = STRATEGY;

  if (filename) {
    // printf("load game from %s\n", filename);
    // TODO : load game from file
    if ( ( seed = load_game( filename )) < 0) {
      seed = time( NULL );         // else use the default seed(=time)
      setgame(seed);
      saveBoard();
    }
  } else {
    if (! seed) {
      seed = time( NULL );         // else use the default seed(=time)
    }
    setgame(seed);
    saveBoard();
  }

  setgui(seed);
  PlayGame(seed);                // play the game( core of the game)
  return (0);
}
Example #7
0
int main(int argc, char *argv[])
{
    enum { GAME_COMPUTER, GAME_NETWORK, GAME_UNKNOWN } game_type = GAME_UNKNOWN;
    char *remote_address = NULL;
    int remote_port;
    int i;
	
    if (argc < 2) {
	printf("Penguin Warrior\n");
	printf("Usage: pw [ mode ] [ option ... ]\n");
	printf("  Game modes (choose one):\n");
	printf("    --computer\n");
	printf("    --client <remote ip address>\n");
	printf("    --server <port number>\n");
	printf("  Display options, for tweaking and experimenting:\n");
	printf("    --fullscreen\n");
	printf("    --hwsurface  (use an SDL hardware surface if possible)\n");
	printf("    --doublebuf  (use SDL double buffering if possible)\n");
	printf("  The display options default to a windowed, software buffer.\n");
	exit(EXIT_FAILURE);
    }

    /* Process command line arguments. There are plenty of libraries for command
       line processing, but our needs are simple in this case. */
    for (i = 0; i < argc; i++) {

	/* Networked or scripted opponent? */
	if (!strcmp(argv[i], "--computer")) {
	    game_type = GAME_COMPUTER;
	    continue;
	} else if (!strcmp(argv[i], "--client")) {
	    game_type = GAME_NETWORK;
	    if (i + 2 >= argc) {
		printf("You must supply an IP address "\
		       "and port number for network games.\n");
		exit(EXIT_FAILURE);
	    }
	    remote_address = argv[i+1];
	    remote_port = atoi(argv[i+2]);
	    i++;
	    continue;

	} else if (!strcmp(argv[i], "--server")) {
	    game_type = GAME_NETWORK;
	    if (++i >= argc) {
		printf("You must supply a port number "\
		       "for --server.\n");
		exit(EXIT_FAILURE);
	    }
	    remote_port = atoi(argv[i]);
	    continue;
			
	    /* Display-related options */
	} else if (!strcmp(argv[i], "--hwsurface")) {
	    hwsurface = 1;
	} else if (!strcmp(argv[i], "--doublebuf")) {
	    doublebuf = 1;
	} else if (!strcmp(argv[i], "--fullscreen")) {
	    fullscreen = 1;
	}
    }

    /* If this is a network game, make a connection. */
    if (game_type == GAME_NETWORK) {

	/* If there's no remote address, the user selected
	   server mode. */
	if (remote_address == NULL) {
	    if (WaitNetgameConnection(remote_port,
				      &netlink) != 0) {
		printf("Unable to receive connection.\n");
		exit(EXIT_FAILURE);
	    }
	} else {
	    if (ConnectToNetgame(remote_address, remote_port,
				 &netlink) != 0) {
		printf("Unable to connect.\n");
		exit(EXIT_FAILURE);
	    }
	}

	opponent_type = OPP_NETWORK;
	printf("Playing in network game against %s.\n", netlink.dotted_ip);

    } else if (game_type == GAME_COMPUTER) {

	opponent_type = OPP_COMPUTER;
	printf("Playing against the computer.\n");

    } else {

	printf("No game type selected.\n");
	exit(EXIT_FAILURE);

    }
	
    /* Initialize our random number generator. */
    initrandom();

    /* Create a mutex to protect the player data. */
    player_mutex = SDL_CreateMutex();
    if (player_mutex == NULL) {
	fprintf(stderr, "Unable to create mutex: %s\n",
		SDL_GetError());
    }

    /* Start our scripting engine. */
    InitScripting();
    if (LoadGameScript("pw.tcl") != 0) {
	fprintf(stderr, "Exiting due to script error.\n");
	exit(EXIT_FAILURE);
    }

    /* Fire up SDL. */
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
	printf("Unable to initialize SDL: %s\n", SDL_GetError());
	exit(EXIT_FAILURE);
    }
    atexit(SDL_Quit);
	
    /* Set an appropriate 16-bit video mode. */
    if (SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16,
			 (hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE) |
			 (doublebuf ? SDL_DOUBLEBUF : 0) |
			 (fullscreen ? SDL_FULLSCREEN : 0)) == NULL) {
	printf("Unable to set video mode: %s\n", SDL_GetError());
	exit(EXIT_FAILURE);
    }
	
    /* Save the screen pointer for later use. */
    screen = SDL_GetVideoSurface();
	
    /* Set the window caption to the name of the game. */
    SDL_WM_SetCaption("Penguin Warrior", "Penguin Warrior");
	
    /* Hide the mouse pointer. */
    SDL_ShowCursor(0);

    /* Initialize the status display. */
    if (InitStatusDisplay() < 0) {
	printf("Unable to initialize status display.\n");
	exit(EXIT_FAILURE);
    }
		
    /* Start the OpenAL-based audio system. */
    InitAudio();

    /* Initialize music and give the music system a file. */
    InitMusic();
    if (LoadMusic("reflux.ogg") < 0) {
	/* If that failed, don't worry about it. */
	printf("Unable to load reflux.ogg.\n");
    }

    /* Load the game's data into globals. */
    LoadGameData();

    /* Initialize the background starfield. */
    InitBackground();

    /* Start the network thread. */
    if (game_type == GAME_NETWORK) {
	network_thread = SDL_CreateThread(NetworkThread, NULL);
	if (network_thread == NULL) {
	    printf("Unable to start network thread: %s\n",
		   SDL_GetError());
	    exit(EXIT_FAILURE);
	}
    }
	
    /* Play! */
    InitPlayer(&player);
    InitPlayer(&opponent);
    PlayGame();

    /* Kill the network thread. */
    if (game_type == GAME_NETWORK) {
	SDL_KillThread(network_thread);
    }

    /* Close the network connection. */
    if (game_type == GAME_NETWORK)
	CloseNetgameLink(&netlink);

    /* Unhide the mouse pointer. */
    SDL_ShowCursor(1);
	
    /* Clean up the status display. */
    CleanupStatusDisplay();

    /* Unload data. */
    UnloadGameData();
	
    /* Shut down our scripting engine. */
    CleanupScripting();

    /* Get rid of the mutex. */
    SDL_DestroyMutex(player_mutex);

    /* Shut down audio. */
    CleanupMusic();
    CleanupAudio();

    return 0;
}
Example #8
0
void ac_EnterPassword()
{
	SDL_Event event;
	MENU *m = &PasswordMenu;
	char pass[16];

	m->num = 51;
	m->sel = 0;
	memset(pass, 0, sizeof(pass));

	done = 0;
	while(!done) {
		while(SDL_PollEvent(&event))
			if(event.type == SDL_KEYDOWN) {
				if(event.key.keysym.sym == SDLK_LEFT) {
					if(m->sel > 0) {
						m->sel--;
						PlaySound(0);
					} else {
						m->sel = m->num - 1;
					}
				} else if(event.key.keysym.sym == SDLK_RIGHT) {
					if(m->sel < m->num - 1) {
						m->sel++;
						PlaySound(0);
					} else {
						m->sel = 0;
					}
				} else if(event.key.keysym.sym == SDLK_LCTRL) {
					if(strlen(pass) < 5) {
						strncat(pass, PassChars + m->sel, 1);
					}
				} else if(event.key.keysym.sym == SDLK_LALT) {
					if(strlen(pass) != 0) {
						pass[strlen(pass) - 1] = 0;
					}
				} else if(event.key.keysym.sym == SDLK_RETURN) {
					int i;

					if((i = check_pass(pass)) != -1 &&
					   (pass[4] == '1' || pass[4] == '2')) {
						PlayGame(NORMAL, i, 0, pass[4] & 3);
						CheckForRecord();
					} else {
						PlaySound(1);
						MPrint("INVALID PASSWORD!!", 190, 255, 252);
						BlitAndWait(50);
					}
					done = 1;
				} else if(event.key.keysym.sym == SDLK_ESCAPE) {
					done = 1;
				}
			}

		SDL_BlitSurface(title, NULL, gamescreen, NULL);
		MPrint(m->header, m->y, m->col, 252);

		DrawLetters(m->sel);
		MPrint(pass, 150, 255, 252);
		PutBox(158, 123, 168, 135, 83);
		PutBox(134, 148, 184, 160, 83);

		MPrint("PRESS LEFT/RIGHT TO SELECT", 170, 255, 252);
		MPrint("<START> TO CONFIRM", 180, 255, 252);

		BlitAndWait(1);
	}

	done = 0;
}
Example #9
0
void ac_StartGame()
{
	PlayGame(NORMAL, 0, 0, MainMenu.sel + 1);
	CheckForRecord();
}
Example #10
0
/*-----------------------------------------------------------------
 * @Desc: play takeover-game against a druid 
 *
 * @Ret: TRUE/FALSE:  user has won/lost
 *
 *-----------------------------------------------------------------*/
int
Takeover (int enemynum)
{
  int row;
  int FinishTakeover = FALSE;
  static int RejectEnergy = 0;	/* your energy if you're rejected */
  char *message;
  SDL_Rect buf;
  Uint32 now;

  /* Prevent distortion of framerate by the delay coming from 
   * the time spend in the menu.
   */
  Activate_Conservative_Frame_Computation ();

  // release fire keys
  SpacePressedR();
  MouseLeftPressedR();

  // Takeover game always uses Classic User_Rect:
  Copy_Rect (User_Rect, buf);
  Copy_Rect (Classic_User_Rect, User_Rect);

  DisplayBanner (NULL, NULL,  BANNER_FORCE_UPDATE );
  
  Fill_Rect (User_Rect, to_bg_color);

  Me.status = MOBILE; /* the new status _after_ the takeover game */

  SDL_ShowCursor (SDL_DISABLE); // no mouse-cursor in takeover game!

  show_droid_info ( Me.type, -1 , 0);
  show_droid_portrait (Cons_Droid_Rect, Me.type, DROID_ROTATION_TIME, UPDATE);
  while (!FirePressedR())
    show_droid_portrait (Cons_Droid_Rect, Me.type, DROID_ROTATION_TIME, 0);

  show_droid_info ( AllEnemys[enemynum].type, -2 ,0);
  show_droid_portrait (Cons_Droid_Rect,  AllEnemys[enemynum].type, DROID_ROTATION_TIME, UPDATE);
  while (!FirePressedR())
    show_droid_portrait (Cons_Droid_Rect,  AllEnemys[enemynum].type, DROID_ROTATION_TIME, 0);

  SDL_BlitSurface (takeover_bg_pic, NULL, ne_screen, NULL);
  DisplayBanner (NULL, NULL,  BANNER_FORCE_UPDATE );

  while (!FinishTakeover)
    {
      /* Init Color-column and Capsule-Number for each opponenet and your color */
      for (row = 0; row < NUM_LINES; row++)
	{
	  DisplayColumn[row] = (row % 2);
	  CapsuleCountdown[GELB][0][row] = -1;
	  CapsuleCountdown[VIOLETT][0][row] = -1;
	}			/* for row */

      YourColor = GELB;
      OpponentColor = VIOLETT;

      CapsuleCurRow[GELB] = 0;
      CapsuleCurRow[VIOLETT] = 0;
      
      DroidNum = enemynum;
      OpponentType = AllEnemys[enemynum].type;
      NumCapsules[YOU] = 3 + ClassOfDruid (Me.type);
      NumCapsules[ENEMY] = 4 + ClassOfDruid (OpponentType);

      InventPlayground ();

      ShowPlayground ();

      ChooseColor ();

      PlayGame ();

      /* Ausgang beurteilen und returnen */
      if (InvincibleMode || (LeaderColor == YourColor))
	{
	  Takeover_Game_Won_Sound ();
	  if (Me.type == DRUID001)
	    {
	      RejectEnergy = Me.energy;
	      PreTakeEnergy = Me.energy;
	    }

	  // We provide some security agains too high energy/health values gained
	  // by very rapid successions of successful takeover attempts
	  if (Me.energy > Druidmap[DRUID001].maxenergy) Me.energy = Druidmap[DRUID001].maxenergy;
	  if (Me.health > Druidmap[DRUID001].maxenergy) Me.health = Druidmap[DRUID001].maxenergy;

	  // We allow to gain the current energy/full health that was still in the 
	  // other droid, since all previous damage must be due to fighting damage,
	  // and this is exactly the sort of damage can usually be cured in refreshes.
	  Me.energy += AllEnemys[enemynum].energy;
	  Me.health += Druidmap[OpponentType].maxenergy;

	  Me.type = AllEnemys[enemynum].type;

	  RealScore += Druidmap[OpponentType].score;

	  DeathCount += OpponentType * OpponentType;   // quadratic "importance", max=529

	  AllEnemys[enemynum].status = OUT; // removed droid silently (no blast!)

	  if (LeaderColor != YourColor)	/* only won because of InvincibleMode */
	    message = "You cheat";
	  else				/* won the proper way */
	    message = "Complete";

	  FinishTakeover = TRUE;
	}				/* LeaderColor == YourColor */
      else if (LeaderColor == OpponentColor)
	{
	  // you lost, but enemy is killed too --> blast it!
	  AllEnemys[enemynum].energy = -1.0;  /* to be sure */

	  Takeover_Game_Lost_Sound ();
	  if (Me.type != DRUID001)
	    {
	      message = "Rejected";
	      Me.type = DRUID001;
	      Me.energy = RejectEnergy;
	    }
	  else
	    {
	      message = "Burnt Out";
	      Me.energy = 0;
	    }
	  FinishTakeover = TRUE;
	}			/* LeadColor == OpponentColor */
      else
	{
	  Takeover_Game_Deadlock_Sound ();
	  message = "Deadlock";
	}			/* LeadColor == REMIS */

      DisplayBanner (message, NULL , 0 );	
      ShowPlayground ();
      now = SDL_GetTicks();
      while ((!FirePressedR()) && (SDL_GetTicks() - now < SHOW_WAIT) ) SDL_Delay(1);

    }	/* while !FinishTakeover */

  // restore User_Rect
  Copy_Rect (buf, User_Rect);

  ClearGraphMem();
  SDL_Flip(ne_screen);

  if (LeaderColor == YourColor)
    return TRUE;
  else
    return FALSE;

} /* Takeover() */
Example #11
0
void GeneticAlgorithm(){

    int maxIter = 100;
    int i,j,k;
    int group[GROUP_SIZE][COUNT_FUNC];
    int oldParameter[COUNT_FUNC];
    int maxIndex;
    double sum,max,min,tmp;
    int count_record = 0;
    char output[300];

    /*初始族群*/
    InitGroup(group);



    for ( i = 0 ; i < maxIter ; i++){
        Eliminate(group);
        Crossover(group);
        Mutation(group);

        sum = 0;
        max = -1;
        min = 20;
        maxIndex = 0;
        #pragma omp parallel for
        for ( j = 0 ; j < GROUP_SIZE ; j++){
            tmp= Evalue( group[j]);

            if ( tmp > 10){
                fout = fopen("parameter.txt", "a");
                sprintf(output,"Parameter = ");
                for ( k = 0 ; k < COUNT_FUNC ; k++){
                    sprintf(output,"%s %5d",output, group[j][k]);
                }
                sprintf(output,"%s, Score = %lf\n",output,tmp);
                fprintf(fout,"%s",output);
                fclose(fout);
            }

            sum += tmp;

            if ( tmp > max ){
                max= tmp;
                maxIndex = j;
            }
            if ( tmp < min )
                min = tmp;
        }
        if ( i % 10 == 0)
            Record(group);
        printf("Level(%d) = %.2lf, %.2lf, %.2lf\n", i,max,sum/GROUP_SIZE,min);
        if ( max >= 10.5 && PlayGame(group[maxIndex]) >= 10.9)
            break;
    }

    printf("==Result==\n");
    for ( i = 0 ; i < COUNT_FUNC ; i++){
        printf(", %d", group[maxIndex][i]);
    }
    putchar('\n');

}
Example #12
0
void Game::Run() {
	int iResult;
	userInterface = UserInterface(true);
	std::string myName = userInterface.InputPlayerName("your");
	while (!mustShutdown) {
		Network::RemoteAddress param;
		switch (userInterface.MenuDialog()) {
		case UserInterface::ExitGame: {
			return;
		}
		case UserInterface::LocalGame: {
			server = new PentagoServer(PentagoServer::DEFAULT_PORT);
			if (!server->IsGood()) {
				userInterface.Show_CanNotStartServer();
				delete server;
				server = 0;
				continue;
			}
			delete players[Player1];
			delete players[Player2];
			players[Player1] = new PlayerLocal(myName);
			players[Player2] = new PlayerLocal(userInterface.InputPlayerName("player 2"));
			param.addr = "127.0.0.1";
			param.port = PentagoServer::DEFAULT_PORT;
			iResult = network.Connect(&param, players, (char) PlayerBoth);
			if (iResult == 0) {
				PlayGame();
			} else {
				userInterface.Show_CanNotConnect(&param);
			}
			delete server;
			server = 0;
			break;
		}
		case UserInterface::StartHost: {
			server = new PentagoServer(PentagoServer::DEFAULT_PORT);
			if (!server->IsGood()) {
				userInterface.Show_CanNotStartServer();
				delete server;
				server = 0;
				continue;
			}
			delete players[Player1];
			delete players[Player2];
			players[Player1] = new PlayerLocal(myName);
			players[Player2] = new PlayerNetwork("");
			param.addr = "127.0.0.1";
			param.port = PentagoServer::DEFAULT_PORT;
			iResult = network.Connect(&param, players, Player1);
			if (iResult == 0) {
				if (network.WaitForConnection()) {
					PlayGame();
				} else {
					//TODO: complete it
				}
			} else {
				userInterface.Show_CanNotConnect(&param);
			}
			delete server;
			server = 0;
			break;
		}
		case UserInterface::ConnectToServer: {
			if (userInterface.GetHostAddress(&param)) {
				delete players[Player2];
				delete players[Player1];
				players[Player1] = new PlayerNetwork("");
				players[Player2] = new PlayerLocal(myName);
				iResult = network.Connect(&param, players, Player2);
				if (iResult == 0) {
					PlayGame();
				} else {
					userInterface.Show_CanNotConnect(&param);
				}
			}
			break;
		}
		}
	}
}
//*****************************************************************************
//
// The main code for the application.  It sets up the peripherals, displays the
// splash screens, and then manages the interaction between the game and the
// screen saver.
//
//*****************************************************************************
int
main(void)
{
    //
    // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    // a workaround to allow the PLL to operate reliably.
    //
    if(REVISION_IS_A2)
    {
        SysCtlLDOSet(SYSCTL_LDO_2_75V);
    }

    //
    // Set the clocking to run at 50MHz from the PLL.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
    SysCtlPWMClockSet(SYSCTL_PWMDIV_8);

    //
    // Get the system clock speed.
    //
    g_ulSystemClock = SysCtlClockGet();

    //
    // Enable the peripherals used by the application.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure the GPIOs used to read the state of the on-board push buttons.
    //
    GPIOPinTypeGPIOInput(GPIO_PORTE_BASE,
                         GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
    GPIOPadConfigSet(GPIO_PORTE_BASE,
                     GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3,
                     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA,
                     GPIO_PIN_TYPE_STD_WPU);

    //
    // Configure the LED, speaker, and UART GPIOs as required.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);

    //
    // Intialize the Ethernet Controller and TCP/IP Stack.
    //
    EnetInit();

    //
    // Configure the first UART for 115,200, 8-N-1 operation.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
    UARTEnable(UART0_BASE);

    //
    // Send a welcome message to the UART.
    //
    UARTCharPut(UART0_BASE, 'W');
    UARTCharPut(UART0_BASE, 'e');
    UARTCharPut(UART0_BASE, 'l');
    UARTCharPut(UART0_BASE, 'c');
    UARTCharPut(UART0_BASE, 'o');
    UARTCharPut(UART0_BASE, 'm');
    UARTCharPut(UART0_BASE, 'e');
    UARTCharPut(UART0_BASE, '\r');
    UARTCharPut(UART0_BASE, '\n');

    //
    // Initialize the OSRAM OLED display.
    //
    RIT128x96x4Init(3500000);

    //
    // Initialize the PWM for generating music and sound effects.
    //
    AudioOn();

    //
    // Configure SysTick to periodically interrupt.
    //
    SysTickPeriodSet(g_ulSystemClock / CLOCK_RATE);
    SysTickIntEnable();
    SysTickEnable();

    //
    // Delay for a bit to allow the initial display flash to subside.
    //
    Delay(CLOCK_RATE / 4);

    //
    // Play the intro music.
    //
    AudioPlaySong(g_pusIntro, sizeof(g_pusIntro) / 2);

    //
    // Display the Texas Instruments logo for five seconds (or twelve seconds
    // if built using gcc).
    //
#if defined(gcc)
    DisplayLogo(g_pucTILogo, 120, 42, 12 * CLOCK_RATE);
#else
    DisplayLogo(g_pucTILogo, 120, 42, 5 * CLOCK_RATE);
#endif

    //
    // Display the Code Composer Studio logo for five seconds.
    //
#if defined(ccs)
    DisplayLogo(g_pucCodeComposer, 128, 34, 5 * CLOCK_RATE);
#endif

    //
    // Display the Keil/ARM logo for five seconds.
    //
#if defined(rvmdk) || defined(__ARMCC_VERSION)
    DisplayLogo(g_pucKeilLogo, 128, 40, 5 * CLOCK_RATE);
#endif

    //
    // Display the IAR logo for five seconds.
    //
#if defined(ewarm)
    DisplayLogo(g_pucIarLogo, 102, 61, 5 * CLOCK_RATE);
#endif

    //
    // Display the CodeSourcery logo for five seconds.
    //
#if defined(sourcerygxx)
    DisplayLogo(g_pucCodeSourceryLogo, 128, 34, 5 * CLOCK_RATE);
#endif

    //
    // Display the CodeRed logo for five seconds.
    //
#if defined(codered)
    DisplayLogo(g_pucCodeRedLogo, 128, 32, 5 * CLOCK_RATE);
#endif

    //
    // Throw away any button presses that may have occurred while the splash
    // screens were being displayed.
    //
    HWREGBITW(&g_ulFlags, FLAG_BUTTON_PRESS) = 0;

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Display the main screen.
        //
        if(MainScreen())
        {
            //
            // The button was pressed, so start the game.
            //
            PlayGame();
        }
        else
        {
            //
            // The button was not pressed during the timeout period, so start
            // the screen saver.
            //
            ScreenSaver();
        }
    }
}
Example #14
0
//*****************************************************************************
//
// The main code for the application.  It sets up the peripherals, displays the
// splash screens, and then manages the interaction between the game and the
// screen saver.
//
//*****************************************************************************
int
main(void)
{
	tRectangle sRect;
#ifndef _TMS320C6X
    unsigned int index;
#endif
	
    SetupIntc();

	
	/* Configuring UART2 instance for serial communication. */
    UARTStdioInit();

#ifdef _TMS320C6X
    CacheEnableMAR((unsigned int)0xC0000000, (unsigned int)0x20000000);
    CacheEnable(L1PCFG_L1PMODE_32K | L1DCFG_L1DMODE_32K | L2CFG_L2MODE_256K);
#else
    /* Sets up 'Level 1" page table entries. 
     * The page table entry consists of the base address of the page
     * and the attributes for the page. The following operation is to
     * setup one-to-one mapping page table for DDR memeory range and set
     * the atributes for the same. The DDR memory range is from 0xC0000000
     * to 0xDFFFFFFF. Thus the base of the page table ranges from 0xC00 to 
     * 0xDFF. Cache(C bit) and Write Buffer(B bit) are enabled  only for
     * those page table entries which maps to DDR RAM and internal RAM.
     * All the pages in the DDR range are provided with R/W permissions
     */
    for(index = 0; index < (4*1024); index++)
    {
         if((index >= 0xC00 && index < 0xE00)|| (index == 0x800))
         {             
              pageTable[index] = (index << 20) | 0x00000C1E;
         }
         else
         {
              pageTable[index] = (index << 20) | 0x00000C12;
         }
    }
     
    /* Configures translation table base register
     * with pagetable base address.
     */
    CP15TtbSet((unsigned int )pageTable);

    /* Enables MMU */
    CP15MMUEnable();
   
	/* Enable Instruction Cache */
    CP15ICacheEnable();

    /* Enable Data Cache */
    CP15DCacheEnable();
#endif

    SetUpLCD();
	
	ConfigureFrameBuffer();
		
	GrOffScreen16BPPInit(&g_sSHARP480x272x16Display0, (unsigned char *)g_pucBuffer0, LCD_WIDTH, LCD_HEIGHT);
	GrOffScreen16BPPInit(&g_sSHARP480x272x16Display1, (unsigned char *)g_pucBuffer1, LCD_WIDTH, LCD_HEIGHT);
	
	// Initialize a drawing context.
	GrContextInit(&sContext0, &g_sSHARP480x272x16Display0);
	GrContextInit(&sContext1, &g_sSHARP480x272x16Display1);

    /* enable End of frame interrupt */
    RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS);

    /* enable raster */
    RasterEnable(SOC_LCDC_0_REGS);

	PeripheralsSetup();
	I2C0IntRegister(4);
    AIC31Init();
    ToneLoopInit();
	/* Start playing the tone */
    ToneLoopStart();
	
    // TS init	
	TouchInit();
	
	GrContextForegroundSet(&sContext0, ClrBlack);
	GrContextForegroundSet(&sContext1, ClrBlack);
    sRect.sXMin = GAME_X - 1;
    sRect.sYMin = GAME_Y - 1;
    sRect.sXMax = GAME_X + GAME_W;
    sRect.sYMax = GAME_Y + GAME_H;
    GrRectFill(&sContext0, &sRect);
    GrRectFill(&sContext1, &sRect);

    GrImageDraw(&sContext0, g_pucTILogo128x96, GAME_X, GAME_Y);
	GrImageDraw(&sContext1, g_pucTILogo128x96, GAME_X, GAME_Y);
	
	Delay(0x5FFFFF);
	
	// Confiure and start timer2
	Timer2Config();
	Timer2Start();

    // Loop forever.
    while(1)
    {
        // Display the main screen.
        if(MainScreen())
        {
            // The button was pressed, so start the game.
            PlayGame();
        }
        else
        {
            // The button was not pressed during the timeout period, so start
            // the screen saver.
            ScreenSaver();
        }
    }
}
Example #15
0
int main(int argc, char *argv[])
{
    enum { GAME_COMPUTER, GAME_NETWORK, GAME_UNKNOWN } game_type = GAME_UNKNOWN;
    char *remote_address;
    int i;
	
    if (argc < 2) {
	printf("Penguin Warrior\n");
	printf("Usage: pw [ mode ] [ option ... ]\n");
	printf("  Game modes (choose one):\n");
	printf("    --computer\n");
	printf("    --net <remote ip address>\n");
	printf("  Display options, for tweaking and experimenting:\n");
	printf("    --fullscreen\n");
	printf("    --hwsurface  (use an SDL hardware surface if possible)\n");
	printf("    --doublebuf  (use SDL double buffering if possible)\n");
	printf("  The display options default to a windowed, software buffer.\n");
	exit(EXIT_FAILURE);
    }

    /* Process command line arguments. There are plenty of libraries for command
       line processing, but our needs are simple in this case. */
    for (i = 0; i < argc; i++) {

	/* Networked or scripted opponent? */
	if (!strcmp(argv[i], "--computer")) {
	    game_type = GAME_COMPUTER;
	    continue;
	} else if (!strcmp(argv[i], "--net")) {
	    game_type = GAME_NETWORK;
	    if (++i >= argc) {
		printf("You must supply an IP address for --net.\n");
		exit(EXIT_FAILURE);
	    }
	    remote_address = argv[i];
	    continue;

	    /* Display-related options */
	} else if (!strcmp(argv[i], "--hwsurface")) {
	    hwsurface = 1;
	} else if (!strcmp(argv[i], "--doublebuf")) {
	    doublebuf = 1;
	} else if (!strcmp(argv[i], "--fullscreen")) {
	    fullscreen = 1;
	}
    }

    switch (game_type) {
    case GAME_COMPUTER:
	opponent_type = OPP_COMPUTER;
	printf("Playing against the computer.\n");
	break; 
			
    case GAME_NETWORK:
	printf("Sorry, network play is not implemented... yet!\n");
	exit(EXIT_FAILURE);
			
    default:
	printf("You must select a game type.\n");
	exit(EXIT_FAILURE);
    }
	
    /* Initialize our random number generator. */
    initrandom();

    /* Fire up SDL. */
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
	printf("Unable to initialize SDL: %s\n", SDL_GetError());
	exit(EXIT_FAILURE);
    }
    atexit(SDL_Quit);
	
    /* Set an appropriate 16-bit double buffered video mode. */
    if (SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16,
			 (hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE) |
			 (doublebuf ? SDL_DOUBLEBUF : 0) |
			 (fullscreen ? SDL_FULLSCREEN : 0)) == NULL) {
	printf("Unable to set video mode: %s\n", SDL_GetError());
	exit(EXIT_FAILURE);
    }
	
    /* Save the screen pointer for later use. */
    screen = SDL_GetVideoSurface();
	
    /* Set the window caption to the name of the game. */
    SDL_WM_SetCaption("Penguin Warrior", "Penguin Warrior");
	
    /* Hide the mouse pointer. */
    SDL_ShowCursor(0);

    /* Start the OpenAL-based audio system. */
    InitAudio();

    /* Initialize music and give the music system a file. */
    InitMusic();
    if (LoadMusic("reflux.ogg") != 0) {
	/* If that failed, don't worry about it. */
	printf("Unable to load reflux.ogg.\n");
    }
		
    /* Load the game's data into globals. We can only do this after the
       video and audio subsystems are ready for action, since the loading
       routines interact with SDL and OpenAL. */
    LoadGameData();

    /* Initialize the background starfield. */
    InitBackground();
	
    /* Play! */
    InitPlayer();
    InitOpponent();
    PlayGame();

    /* Unhide the mouse pointer. */
    SDL_ShowCursor(1);
	
    /* Unload data. */
    UnloadGameData();

    /* Shut down audio. */
    CleanupMusic();
    CleanupAudio();

    return 0;
}